Skip to content

Better Circle Scanning#910

Open
Stick404 wants to merge 2 commits into
FallingColors:mainfrom
Stick404:FutureScanning
Open

Better Circle Scanning#910
Stick404 wants to merge 2 commits into
FallingColors:mainfrom
Stick404:FutureScanning

Conversation

@Stick404
Copy link
Copy Markdown
Contributor

Improves Spell Circle scanning by making a custom system to use ServerChunkCache#getChunkFuture's quicker chunk loading.
Creates a Helper Class in case spells/addons wish to use this system

Comment on lines +24 to +57
fun cacheChunk(chunk: ChunkPos): Boolean {
val chunkLong = chunk.toLong()
// We have the chunk already, so we can skip it
if (chunks.contains(chunkLong)){
return true
}
val future = level.chunkSource.getChunkFuture(chunk.x,chunk.z, ChunkStatus.EMPTY,true).get()
if (future.left().isPresent){
chunks.put(chunkLong, future.left().get() as ImposterProtoChunk)
return true
}
HexAPI.LOGGER.warn("Failed to get chunk at {}!",chunk)
return false
}

fun cacheChunk(chunk: Long): Boolean{
return cacheChunk(ChunkPos(chunk))
}

fun getBlock(blockPos: BlockPos): BlockState? {
val chunkPos = ChunkPos(blockPos).toLong()
if (!cacheChunk(chunkPos)){
return null
}
return chunks.get(chunkPos).getBlockState(blockPos)
}

fun getBlockEntity(blockPos: BlockPos): BlockEntity? {
val chunkPos = ChunkPos(blockPos).toLong()
if (!cacheChunk(chunkPos)){
return null
}
return chunks.get(chunkPos).getBlockEntity(blockPos)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fun cacheChunk(chunk: ChunkPos): Boolean {
val chunkLong = chunk.toLong()
// We have the chunk already, so we can skip it
if (chunks.contains(chunkLong)){
return true
}
val future = level.chunkSource.getChunkFuture(chunk.x,chunk.z, ChunkStatus.EMPTY,true).get()
if (future.left().isPresent){
chunks.put(chunkLong, future.left().get() as ImposterProtoChunk)
return true
}
HexAPI.LOGGER.warn("Failed to get chunk at {}!",chunk)
return false
}
fun cacheChunk(chunk: Long): Boolean{
return cacheChunk(ChunkPos(chunk))
}
fun getBlock(blockPos: BlockPos): BlockState? {
val chunkPos = ChunkPos(blockPos).toLong()
if (!cacheChunk(chunkPos)){
return null
}
return chunks.get(chunkPos).getBlockState(blockPos)
}
fun getBlockEntity(blockPos: BlockPos): BlockEntity? {
val chunkPos = ChunkPos(blockPos).toLong()
if (!cacheChunk(chunkPos)){
return null
}
return chunks.get(chunkPos).getBlockEntity(blockPos)
}
fun cacheChunk(chunk: ChunkPos): ImposterProtoChunk? {
val chunkLong = chunk.toLong()
// If we have the chunk already, we can skip fetching it
val existing = chunks.get(chunkLong)
if (existing != null){
return existing
}
val future = level.chunkSource.getChunkFuture(chunk.x,chunk.z, ChunkStatus.EMPTY,true).get()
if (future.left().isPresent){
val next = future.left().get() as ImposterProtoChunk
chunks.put(chunkLong, next)
return next
}
HexAPI.LOGGER.warn("Failed to get chunk at {}!",chunk)
return null
}
fun cacheChunk(chunk: Long): ImposterProtoChunk? {
return cacheChunk(ChunkPos(chunk))
}
fun getBlock(blockPos: BlockPos): BlockState? {
val chunkPos = ChunkPos(blockPos).toLong()
return cacheChunk(chunkPos)?.getBlockState(blockPos)
}
fun getBlockEntity(blockPos: BlockPos): BlockEntity? {
val chunkPos = ChunkPos(blockPos).toLong()
return cacheChunk(chunkPos)?.getBlockEntity(blockPos)
}

}
val future = level.chunkSource.getChunkFuture(chunk.x,chunk.z, ChunkStatus.EMPTY,true).get()
if (future.left().isPresent){
chunks.put(chunkLong, future.left().get() as ImposterProtoChunk)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this cast safe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 📋 Backlog

Development

Successfully merging this pull request may close these issues.

2 participants